#include<iostream>
using namespace std;

void solve1() {
	int n;
	cin >> n;
	int trp = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (trp < 10)
				cout << 0;
			cout << trp;
			trp++;
		}
		cout << '\n';
	}
	cout << '\n';
	trp = 1;
	for (int i = 1; i <= n; ++i) {

		for (int p = n - i; p > 0; --p)
			cout << "  ";

		for (int j = 1; j <= i; ++j) {
			if (trp < 10)
				cout << 0;
			cout << trp;
			trp++;
		}
		cout << '\n';
	}

	return;
}

void solve2() {
	int N;
	cin >> N;
	N /= 52;
	N /= 7;

	for (int k = 1;; ++k) {
		int trp = N - 3 * k;
		if (trp <= 100) {
			cout << trp << '\n' << k;
			return;
		}
	}
	return;
}

int a[13];
void solve3() {
	for (int i = 1; i <= 12; ++i) {
		cin >> a[i];
	}
	int bank = 0;
	int ans = 0;
	for (int i = 1; i <= 12; ++i) {
		ans += 300;
		ans -= a[i];
		if (ans < 0) {
			cout << "-" << i;
			return;
		}

		if (ans / 100 != 0) {
			int sss = ans / 100;
			bank = bank + sss * 100;
			ans = ans - sss * 100;
		}
	}
	ans = ans + bank * 1.2;
	cout << ans;

	return;
}


bool check(int x) {
	for (int i = 2; i <= sqrt(x); ++i) {
		if (x % i == 0)
			return false;
	}

	return true;
}

void solve4() {
	int n;
	cin >> n;
	for (int i = 2; i <= n / 2; ++i) {

		if (n % i != 0) continue;
		if(!check(i)) continue;
		
		int temp = n / i;
		if (check(temp)) {
			int ret = max(temp, i);
			cout << ret;
			return;
		}
	}
	return;
}

int n;

char m_begin[11][11];
char result[11][11];
char temp[11][11];

bool step1() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[j][n - 1 - i] = m_begin[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	cout << 1;
	return true;
}
bool step2() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[n - 1 - i][n - 1 - j] = m_begin[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	cout << 2;
	return true;
}
bool step3() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[n - 1 - j][i] = m_begin[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	cout << 3;
	return true;
}
bool step4() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[i][n - 1 - j] = m_begin[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	cout << 4;
	return true;
}

bool check5_1() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[n - j - 1][n - 1 - i] = m_begin[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	return true;
}

bool check5_2() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[n - 1 - i][j] = m_begin[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	return true;
}

bool check5_3() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			temp[j][i] = m_begin[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (temp[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	return true;
}

bool step5() {
	if (check5_1() || check5_2() || check5_3()) {
		cout << 5;
		return true;
	}
	return false;
	
}
bool step6() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (m_begin[i][j] == result[i][j])
				continue;
			else
				return false;
		}
	}
	cout << 6;
	return true;
}


bool choose(int x) {
	switch (x) {
		case 1:
			if (step1())
				return true;
			return false;
		case 2:
			if (step2())
				return true;
			return false;
		case 3:
			if (step3())
				return true;
			return false;
		case 4:
			if (step4())
				return true;
			return false;
		case 5:
			if (step5())
				return true;
			return false;
		case 6:
			if (step6())
				return true;
			return false;		
	}
	//if (x == 7)没有符合条件的操作
	cout << 7;
	return true;
}

void caozuo() {
	
	for (int i = 1; i <= 7; ++i) {
		if (choose(i))
			break;
	}
	return;
}


void solve5() {
	cin >> n;
	//初始化起始数组
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < n; ++j) {
			m_begin[i][j] = s[j];
		}
	}
	//初始化结果数组
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < n; ++j) {
			result[i][j] = s[j];
		}
	}	
	caozuo();

	return;
}

int main() {

	//solve1();
	//solve2();
	//solve3();
	//solve4();
	solve5();

	return 0;
}